#!/usr/bin/env sh
set -x

NDK_PATH="/home/XXXX/dev/libs/ndk_compile/android-ndk-r23b"  # TODO MODIFY THIS PATH
CMAKE_TOOLCHAIN_PATH="${NDK_PATH}/build/cmake/android.toolchain.cmake"
INSTALL_PATH="../../ceres_210_install"

echo "build target lib xxx for android"

function build_cmn
{
    rm -rf ${INSTALL_PATH}

    mkdir -p build
    cd build

    ARCH_ABI=arm64-v8a
    API_LEVEL=26
    echo "----------------------------------"
    echo ${API_LEVEL}
    cmake \
    -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_PATH} \
    -DANDROID_ABI=${ARCH_ABI} \
    -DANDROID_NDK=${NDK_PATH} \
    -DANDROID_PLATFORM="android-${API_LEVEL}" \
    -DANDROID_NATIVE_API_LEVEL=${API_LEVEL} \
    -DBUILD_ANDROID_PROJECTS=OFF \
    -DBUILD_ANDROID_EXAMPLES=OFF \
    -DCMAKE_BUILD_TYPE=Release  \
    -DEigen3_DIR=/home/w/dev/libs/ndk_compile/eigen/eigen_install/share/eigen3/cmake \
    -Dgflags_DIR=./../gflags_install/lib/cmake/gflags \
    -DGlog_DIR=./../glog_install/lib/cmake/glog \
-DCMAKE_INSTALL_PREFIX=${INSTALL_PATH} ..

    # currently
    # eigen3 为  5.0.1
    # glog 为 0.8.0
    # gflags 为 2.2.2

    #make clean
    make -j8
    make install
}

# build_cmn armeabi-v7a 16 NDK_PATH
build_cmn
